package cn.bonoon.kernel.web.handlers;

import cn.bonoon.handler.impl.StandardAutoManager;
import cn.bonoon.kernel.events.OperateEvent;
import cn.bonoon.kernel.support.entities.Persistable;
import cn.bonoon.kernel.support.models.ObjectEditor;
import cn.bonoon.kernel.support.services.GenericService;


public class OperateUpdateHandler<E extends Persistable> extends AbstractOperateFormHandler<E> {

	public OperateUpdateHandler(GenericService<E> service, StandardAutoManager initializer, Class<?> editClass) throws Exception{
		super(SAVE_UPDATE, service, initializer, editClass);
	}

	@Override
	protected final E internalExecute(OperateEvent event, ObjectEditor editor)throws Exception {
		if(!editor.isNew()){
			return executeUpdate(event, editor);
		}
		throw new RuntimeException("");
	}
	
	protected E executeUpdate(OperateEvent event, ObjectEditor editor)throws Exception{
		return service.update(event, editor.getId());
	}
}
